package com.lzx.mumianaicodegenerator.core.saver;

import cn.hutool.core.util.StrUtil;
import com.lzx.mumianaicodegenerator.ai.model.enums.CodeGenTypeEnum;
import com.lzx.mumianaicodegenerator.ai.model.HtmlCodeResult;
import com.lzx.mumianaicodegenerator.exception.BusinessException;
import com.lzx.mumianaicodegenerator.exception.ErrorCode;

public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult> {
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void saveFiles(HtmlCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath,"index.html",result.getHtmlCode());
    }

    @Override
    protected void validateInput(HtmlCodeResult result){
        super.validateInput(result);
        if (StrUtil.isBlank(result.getHtmlCode())) throw new BusinessException(ErrorCode.SYSTEM_ERROR, "保存文件失败，htmlCode为空");
    }
}
